﻿namespace FiftyOne.Foundation.Mobile.Detection.Wurfl.Handlers
{
    using FiftyOne.Foundation.Mobile.Detection.Wurfl;
    using System;

    internal class OperaDesktopHandler : RegexSegmentHandler
    {
        private const string DEFAULT_DEVICE = "opera";
        private const byte EXTRA_CONFIDENCE = 1;
        private static readonly string PATTERN = @"(?<=$Opera/)[\d+.]+|(?<=Opera )[\d+.]+";
        private static readonly string[] SUPPORTED_ROOT_DEVICES = new string[] { "opera" };

        public OperaDesktopHandler() : base(PATTERN)
        {
        }

        protected internal override bool CanHandle(string userAgent)
        {
            return (((InternalCanHandle(userAgent) && !OperaMiniHandler.InternalCanHandle(userAgent)) && !OperaMobiHandler.InternalCanHandle(userAgent)) && base.CanHandle(userAgent));
        }

        internal static bool InternalCanHandle(string userAgent)
        {
            return userAgent.StartsWith("Opera");
        }

        internal override byte Confidence
        {
            get
            {
                return (byte) (base.Confidence + 1);
            }
        }

        internal override DeviceInfo DefaultDevice
        {
            get
            {
                DeviceInfo deviceInfoFromID = Provider.Instance.GetDeviceInfoFromID("opera");
                if (deviceInfoFromID != null)
                {
                    return deviceInfoFromID;
                }
                return base.DefaultDevice;
            }
        }

        protected override string[] SupportedRootDeviceIds
        {
            get
            {
                return SUPPORTED_ROOT_DEVICES;
            }
        }
    }
}

